package cn.com.idmy.base.util;


import cn.com.idmy.base.IdGenerator;
import org.dromara.hutool.core.convert.ConvertUtil;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Type;

public class IdUtil {
    private static IdGenerator<?> generator;

    public static void generator(IdGenerator<?> generator) {
        IdUtil.generator = generator;
    }

    public static <T> T getId(Type idType, Class<?> entityType, @Nullable Object params) {
        return ConvertUtil.convert(idType, generator.generate(entityType, params));
    }

    public static long getSnowflakeId() {
        return org.dromara.hutool.core.data.id.IdUtil.getSnowflake().next();
    }
}
